library(tidyverse)
library(cepespR)
library(readxl)
library(data.table)
library(stargazer)
library(ggplot2)
library(dplyr)
library(hrbrthemes)
library(ggthemes)
library(viridis)


#utilizar arquivos: "grafico_1" e "grafico_2"
library(readr)
grafico_1 <- read_delim("grafico_1.csv", 
                        delim = ";", escape_double = FALSE, locale = locale(decimal_mark = ",", 
                                                                            grouping_mark = ".", encoding = "WINDOWS-1252"), 
                        trim_ws = TRUE)


library(readr)
grafico_2 <- read_delim("grafico_2.csv", 
                        delim = ";", escape_double = FALSE, locale = locale(decimal_mark = ",", 
                                                                            grouping_mark = ".", encoding = "WINDOWS-1252"), 
                        trim_ws = TRUE)

#gráfico_deputado_federal

dados1<-filter(grafico_1,Distancia>=15)
dados1%>%
  ggplot( aes(x=Distancia, y=Valor,group=Variável, color=Variável)) +
  geom_hline(yintercept=0, color="black", linetype="12345678",size=1.2)+
  geom_line(size=1.5,linetype="solid") +
  geom_point(shape=21, color="black", fill="lightgoldenrodyellow", size=1.5)+
  theme_gdocs() + 
  scale_color_gdocs()+
  theme(legend.position = "bottom")+
  theme(legend.direction = "horizontal")+
  scale_x_continuous(limits = c(0,500),breaks = c(0,45, 100,200,300,500)) + 
  scale_y_continuous(limits = c(-0.4,2),breaks = c(-0.3,0,0.3,0.7,1,1.5,2)) + 
  
  labs(y="Coeficientes ", x="Distância")+
  guides(col=guide_legend("Variáveis:"))+
  scale_colour_manual(values=c(Incumbente="red",
                               Experiencia_Municipal="saddlebrown",Experiencia_Estadual="limegreen"))

#gráfico_deputado_estadual


dados2<-filter(grafico_2,Distância>=10)
dados2%>%
  ggplot( aes(x=Distância, y=Valor,group=Variável, color=Variável)) +
  geom_line(size=1.1,linetype="solid") +
  geom_point(shape=21, color="black", fill="lightgoldenrodyellow", size=1.5)+
  theme_gdocs() + 
  scale_color_gdocs()+
  theme(legend.position = "bottom")+
  theme(legend.direction = "horizontal")+
  scale_x_continuous(limits = c(0,500),breaks = c(10,25,100,200,300,500)) + 
  scale_y_continuous(limits = c(-0.41,2.1),breaks = c(0,1.92)) + 
  geom_hline(yintercept=0, color="black", linetype="12345678",size=1.2)+
  labs(y="Coeficientes ", x="Distância")+
  guides(col=guide_legend("Variáveis:"))+
  scale_colour_manual(values=c(Incumbente="red",Experiencia_Municipal="saddlebrown"))








